//
//  LMNavigationViewController.m
//  LM
//
//  Created by Kien Tran on 1/19/13.
//  Copyright (c) 2013 Kien Tran. All rights reserved.
//

#import "LMNavigationViewController.h"
#import "LMConstant.h"
#import "LMHeartButton.h"
#import "LMSettingViewController.h"

@interface LMNavigationViewController () {

    LMHeartButton *_heartButton;
}

@end

@implementation LMNavigationViewController
@synthesize lmViewControllers = _viewControllers, lmSettingViewController = _lmSettingViewController, lmViewController = _lmViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
 //   [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"_0006_bg-nav.png"] forBarMetrics:UIBarMetricsDefault];
  //  [[UIView appearance] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"_0007_Layer-3.png"]]];
    
    //Remove default bg of navigation bar
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:kIMAGE_BG_NAV] forBarMetrics:UIBarMetricsDefault];
    for (UIView *view in self.navigationBar.subviews) {
        if ([NSStringFromClass([view class]) isEqualToString:@"UINavigationBarBackground"]) {
            [view removeFromSuperview];
        }
    }
    
    //Set bg
    [self.navigationBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:kIMAGE_BG_NAV]]];
   
       
    

    // Set heart button
    UIImageView *heartBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kIMAGE_BG_HEART]];
    CGRect heartBGRect = CGRectMake(0, 20, 116, 83);
    [heartBG setFrame:heartBGRect];
    [heartBG setCenter:self.view.center];
    heartBGRect = heartBG.frame;
    heartBGRect.origin.y = 20;
    heartBG.frame = heartBGRect;
    [self.view addSubview:heartBG];
    
    _heartButton= [LMHeartButton buttonWithType:UIButtonTypeCustom];
    _heartButton.valuePercent = 80;
    [_heartButton addTarget:self action:@selector(touchHomeBarButton:) forControlEvents:UIControlEventTouchUpInside];
    [_heartButton setCenter:self.view.center];
    CGRect heartRect = _heartButton.frame;
    heartRect.origin.y = 21;
    _heartButton.frame = heartRect;
    
    [self.view addSubview:_heartButton];
    
    // Set view bg
    [self.view setBackgroundColor:kCOLOR_BG];
    
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [rightButton setTitle:@"Setting" forState:UIControlStateNormal];
    [rightButton setFrame:CGRectMake(241, 24, 72, 37)];
    [rightButton addTarget:self action:@selector(touchRightBarButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightButton];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
//    self.lmViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LMViewController"];
//    self.lmSettingViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LMSettingViewController"];
//    [self.lmViewControllers addObject:self.lmViewController];
//    [self.lmViewControllers addObject:self.lmSettingViewController];
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(touchHomeBarButton:)];
    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    
    [self.view addGestureRecognizer:swipeLeft];
    
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(touchRightBarButton:)];
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    
    [self.view addGestureRecognizer:swipeRight];
   }

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)touchRightBarButton:(id)sender {
    [self.tabBarController setSelectedIndex:1];
}

- (void)touchHomeBarButton:(id)sender {
    [self.tabBarController setSelectedIndex:0];
}
@end
